import {onBeforeUnmount, onMounted, reactive} from "vue";

export default function () {
    // 实现鼠标打点相关的数据
    let point = reactive({
        x: 0,
        y: 0
    });

    // 实现鼠标打点的方法
    function savePoint(e) {
        point.x = e.pageX;
        point.y = e.pageY;
    }

    // 实现鼠标打点的钩子
    onMounted(() => {
        window.addEventListener('click', savePoint);
    });
    onBeforeUnmount(() => {
        // 卸载时移除点击事件
        window.removeEventListener('click', savePoint);
    });
    return point;
}